<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Closest Toeplitz SDP search.</title>
<link rel="canonical" href="/Users/mcgrant/Projects/CVX/examples/html/closest_toeplitz_psd.html">
<link rel="stylesheet" href="../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Closest Toeplitz SDP search.</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% This script finds a Toeplitz Hermitian PSD matrix that is closest to a</span>
<span class="comment">% given Hermitian matrix, as measured by the Frobenius norm. That is, for</span>
<span class="comment">% a given matrix P, it solves:</span>
<span class="comment">%    minimize   || Z - P ||_F</span>
<span class="comment">%    subject to Z &gt;= 0</span>
<span class="comment">%</span>
<span class="comment">% Adapted from an example provided in the SeDuMi documentation. Notice</span>
<span class="comment">% the use of SDP mode to simplify the semidefinite constraint.</span>

<span class="comment">% The data. P is Hermitian, but is neither Toeplitz nor PSD.</span>
P = [ 4,     1+2*j,     3-j       ; <span class="keyword">...</span>
      1-2*j, 3.5,       0.8+2.3*j ; <span class="keyword">...</span>
      3+j,   0.8-2.3*j, 4         ];

<span class="comment">% Construct and solve the model</span>
n = size( P, 1 );
cvx_begin <span class="string">sdp</span>
    variable <span class="string">Z(n,n)</span> <span class="string">hermitian</span> <span class="string">toeplitz</span>
    dual <span class="string">variable</span> <span class="string">Q</span>
    minimize( norm( Z - P, <span class="string">'fro'</span> ) )
    Z &gt;= 0 : Q;
cvx_end

<span class="comment">% Display resuls</span>
disp( <span class="string">'The original matrix, P: '</span> );
disp( P )
disp( <span class="string">'The optimal point, Z:'</span> );
disp( Z )
disp( <span class="string">'The optimal dual variable, Q:'</span> );
disp( Q )
disp( <span class="string">'min( eig( Z ) ), min( eig( Q ) ) (both should be nonnegative, or close):'</span> );
disp( sprintf( <span class="string">'   %g   %g\n'</span>, min( eig( Z ) ), min( eig( Q ) ) ) );
disp( <span class="string">'The optimal value, || Z - P ||_F:'</span> );
disp( norm( Z - P, <span class="string">'fro'</span> ) );
disp( <span class="string">'Complementary slackness: Z * Q, should be near zero:'</span> );
disp( Z * Q )
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling SDPT3 4.0: 20 variables, 6 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints =  6
 dim. of sdp    var  =  6,   num. of sdp  blk  =  1
 dim. of socp   var  = 11,   num. of socp blk  =  1
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|1.8e+01|2.7e+00|7.4e+02| 1.260000e+02  0.000000e+00| 0:0:00| chol  1  1 
 1|0.332|1.000|1.2e+01|3.3e-02|4.7e+02| 9.616817e+01 -4.813672e+01| 0:0:00| chol  1  1 
 2|1.000|1.000|2.4e-07|3.3e-03|3.1e+01| 4.813335e+00 -2.613716e+01| 0:0:00| chol  1  1 
 3|1.000|0.793|9.3e-08|9.5e-04|7.1e+00| 2.763897e+00 -4.276057e+00| 0:0:00| chol  1  1 
 4|0.780|1.000|2.8e-08|3.3e-05|1.9e+00|-9.411558e-01 -2.847823e+00| 0:0:00| chol  1  1 
 5|0.979|0.962|8.9e-10|4.5e-06|6.6e-02|-1.414992e+00 -1.480982e+00| 0:0:00| chol  1  1 
 6|0.983|0.989|1.3e-10|3.8e-07|9.5e-04|-1.450304e+00 -1.451248e+00| 0:0:00| chol  1  1 
 7|0.939|0.983|9.0e-10|3.9e-08|3.9e-05|-1.450788e+00 -1.450827e+00| 0:0:00| chol  1  1 
 8|0.932|0.984|2.0e-09|6.7e-10|1.8e-06|-1.450803e+00 -1.450804e+00| 0:0:00| chol  1  1 
 9|0.981|0.990|1.0e-10|6.6e-11|5.7e-08|-1.450803e+00 -1.450804e+00| 0:0:01|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   =  9
 primal objective value = -1.45080348e+00
 dual   objective value = -1.45080354e+00
 gap := trace(XZ)       = 5.69e-08
 relative gap           = 1.46e-08
 actual relative gap    = 1.45e-08
 rel. primal infeas (scaled problem)   = 1.04e-10
 rel. dual     "        "       "      = 6.61e-11
 rel. primal infeas (unscaled problem) = 0.00e+00
 rel. dual     "        "       "      = 0.00e+00
 norm(X), norm(y), norm(Z) = 1.9e+00, 3.2e+00, 6.8e+00
 norm(A), norm(b), norm(C) = 5.5e+00, 2.0e+00, 8.0e+00
 Total CPU time (secs)  = 0.51  
 CPU time per iteration = 0.06  
 termination code       =  0
 DIMACS: 1.0e-10  0.0e+00  1.0e-10  0.0e+00  1.4e-08  1.5e-08
-------------------------------------------------------------------
 
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +1.4508
 
The original matrix, P: 
   4.0000 + 0.0000i   1.0000 + 2.0000i   3.0000 - 1.0000i
   1.0000 - 2.0000i   3.5000 + 0.0000i   0.8000 + 2.3000i
   3.0000 + 1.0000i   0.8000 - 2.3000i   4.0000 + 0.0000i

The optimal point, Z:
   4.2827 + 0.0000i   0.8079 + 1.7342i   2.5574 - 0.7938i
   0.8079 - 1.7342i   4.2827 + 0.0000i   0.8079 + 1.7342i
   2.5574 + 0.7938i   0.8079 - 1.7342i   4.2827 + 0.0000i

The optimal dual variable, Q:
   0.3366 + 0.0000i  -0.0635 - 0.2866i  -0.3051 + 0.1422i
  -0.0635 + 0.2866i   0.2561 + 0.0000i  -0.0635 - 0.2866i
  -0.3051 - 0.1422i  -0.0635 + 0.2866i   0.3366 + 0.0000i

min( eig( Z ) ), min( eig( Q ) ) (both should be nonnegative, or close):
   1.08289e-08   2.176e-09

The optimal value, || Z - P ||_F:
    1.4508

Complementary slackness: Z * Q, should be near zero:
   1.0e-05 *

   0.0915 - 0.1253i  -0.1237 - 0.0530i  -0.0286 + 0.1516i
   0.0448 - 0.2020i  -0.1790 - 0.0000i   0.0448 + 0.2020i
  -0.0286 - 0.1516i  -0.1237 + 0.0530i   0.0915 + 0.1253i

</pre>
</div>
</body>
</html>